package email;

import cn.itsource.App;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = App.class)
public class SendEmailtest {
    @Autowired
    private JavaMailSender javaMailSender;
     @Test
         public void  sendemil() throws MessagingException {
         //创建复杂邮件对象
         MimeMessage message = javaMailSender.createMimeMessage();
         //工具类向空的邮件发送内容
         MimeMessageHelper helper = new MimeMessageHelper(message,true,"utf-8");
         //设置发件人
         helper.setFrom("1340550289@qq.com");

         //设置邮件主题
         helper.setSubject("诸子百家—纵横");
         //设置邮件内容(格式是h1标题)
         helper.setText("<h1>苍生涂涂,天下燎燎,诸子百家,唯我纵横</h1>"+"<img src='https://timgsa.baidu.com/timg?image&amp;quality=80&amp;size=b9999_10000&amp;sec=1608276940647&amp;di=a57751aa5fdbd7b8f8e3885ab316d972&amp;imgtype=0&amp;src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201708%2F12%2F20170812184924_3HwFU.jpeg'/>",true);
         //添加附件
         helper.addAttachment("19.jpg",new File("C:\\Users\\Administrator\\Desktop\\19.jpg"));
         helper.addAttachment("1.txt", new File("C:\\Users\\Administrator\\Desktop\\1.txt"));
         //设置收件人
         helper.setTo("1783937834@qq.com");
         javaMailSender.send(message);
        for (int i=0;i<3;i++){
            javaMailSender.send(message);
        }
     }
}
